package cn.com.headfree.welfare.service.impl;

import cn.com.headfree.welfare.entity.FlRegistrationdeath;
import cn.com.headfree.welfare.dao.FlRegistrationdeathDao;
import cn.com.headfree.welfare.service.FlRegistrationdeathService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (FlRegistrationdeath)表服务实现类
 *
 * @author makejava
 * @since 2021-12-20 21:01:06
 */
@Service("flRegistrationdeathService")
public class FlRegistrationdeathServiceImpl implements FlRegistrationdeathService {
    @Resource
    private FlRegistrationdeathDao flRegistrationdeathDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FlRegistrationdeath queryById(Integer id) {
        return this.flRegistrationdeathDao.queryById(id);
    }

    /**
     * 查询多条数据
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<FlRegistrationdeath> queryAllByLimit(int offset, int limit) {
        return this.flRegistrationdeathDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param flRegistrationdeath 实例对象
     * @return 实例对象
     */
    @Override
    public FlRegistrationdeath insert(FlRegistrationdeath flRegistrationdeath) {
        if(flRegistrationdeath.getDwmcId()!=null){
            flRegistrationdeath.setDwmc(flRegistrationdeathDao.getOrgName(flRegistrationdeath.getDwmcId()));
        }
        if(flRegistrationdeath.getType()!=null){
            flRegistrationdeath.setTypeName(flRegistrationdeathDao.getTypeVal(flRegistrationdeath.getType()));
        }
        this.flRegistrationdeathDao.insert(flRegistrationdeath);
        return flRegistrationdeath;
    }

    /**
     * 修改数据
     *
     * @param flRegistrationdeath 实例对象
     * @return 实例对象
     */
    @Override
    public FlRegistrationdeath update(FlRegistrationdeath flRegistrationdeath ) {
        if(flRegistrationdeath.getDwmcId()!=null){
            flRegistrationdeath.setDwmc(flRegistrationdeathDao.getOrgName(flRegistrationdeath.getDwmcId()));
        }
        if(flRegistrationdeath.getType()!=null){
            flRegistrationdeath.setTypeName(flRegistrationdeathDao.getTypeVal(flRegistrationdeath.getType()));
        }
        this.flRegistrationdeathDao.update(flRegistrationdeath);
        return this.queryById(flRegistrationdeath.getId());

    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.flRegistrationdeathDao.deleteById(id) > 0;
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param flRegistrationdeath 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo<FlRegistrationdeath> queryAll(FlRegistrationdeath flRegistrationdeath){
        PageHelper.startPage(flRegistrationdeath.getPage(), flRegistrationdeath.getPageSize());
        flRegistrationdeath.setDelSign(0);
        List<FlRegistrationdeath> list =this.flRegistrationdeathDao.queryAll(flRegistrationdeath);
        PageInfo<FlRegistrationdeath> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
